import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
//enum 枚举
enum  Option{A,B,C}
class SimpleDialogDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => SimpleDialogState();
}

class SimpleDialogState extends State<SimpleDialogDemo> {
  String _choice='';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('SimpleDialogDemo'),
        centerTitle: true,
      ),
      body: Container(
        padding: EdgeInsets.all(15),
        child: Text('你的选择：$_choice'),

      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {
          _openSimpleDialog();
        }
      ),
    );
  }

//Future、async、await 异步操作
Future _openSimpleDialog() async{
 final option=await showDialog(
   context: context,
   builder: (BuildContext context){
     return SimpleDialog(
       title: Text('选择工种'),
       children: <Widget>[
         SimpleDialogOption(
           child: Text('项目经理'),
           onPressed: (){
             Navigator.of(context).pop(Option.A);
           },
         ),
         SimpleDialogOption(
           child: Text('总监理'),
           onPressed: (){
             Navigator.of(context).pop(Option.B);
           },
         ),
         SimpleDialogOption(
           child: Text('普通'),
           onPressed: (){
             Navigator.of(context).pop(Option.C);
           },
         ),
       ],
     );
   }
 );
 switch(option){
   case Option.A:
     setState(() {
       _choice='A';
     });
     break;
   case Option.B:
     setState(() {
       _choice='B';
     });
     break;
   case Option.C:
     setState(() {
       _choice='C';
     });
     break;
 }


}

}
